<!-- 
时间 : 2025.01.03:15.12.57
名称 : G_Head
类型 : component
功能 : 全部头部显示（刷新、查询、消息、全屏、头像、折叠、等）
编码 : 村长有人偷包谷
 -->
<script setup>
import P_store from '@store/login/index'
import { defineStore,storeToRefs } from 'pinia'


const store = defineStore('main', {})()
const P = P_store()
const { userName } = storeToRefs(P)


const O_Refresh = () => {
  store.M.To(0)
}
const O_Full = () => {
  var de = document.documentElement;
  if (de.requestFullscreen) {
    de.requestFullscreen();
  } else if (de.mozRequestFullScreen) {
    de.mozRequestFullScreen();
  } else if (de.webkitRequestFullScreen) {
    de.webkitRequestFullScreen();
  }

  if (document.exitFullscreen) {
    document.exitFullscreen();
  } else if (document.mozCancelFullScreen) {
    document.mozCancelFullScreen();
  } else if (document.webkitExitFullscreen) {
    document.webkitExitFullscreen();
  }
}

// 退出登陆
const O_Logout = () => {
  window.location.href = 'http://localhost:8080/'
}


</script>

<template>
  <div id='G_Head'>
    <div style="line-height: 50px;display: flex;white-space: nowrap;">
      <div style="vertical-align:middle;font-size: 14px;">
        {{ store.M.title }}
      </div>
    </div>
    <div class="function">
      <div class="item" @click="O_Refresh">
        <el-tooltip class="box-item" effect="dark" content="刷新页面" placement="bottom">
          <el-icon style="font-size: 16px;">
            <Refresh />
          </el-icon>
        </el-tooltip>
      </div>

    



      <div class="item none">
        <el-tooltip class="box-item" effect="dark" content="功能查询" placement="bottom">
          <el-icon style="font-size: 16px;">
            <Search />
          </el-icon>
        </el-tooltip>
      </div>
      <div class="item none" @click="O_Full">
        <el-tooltip class="box-item" effect="dark" content="全屏显示" placement="bottom">
          <el-icon style="font-size: 16px;">
            <FullScreen />
          </el-icon>
        </el-tooltip>
      </div>



      <div class="info">
        <img style="width:32px;border-radius: 50%;height: 32px" src="@/assets/tx.png" alt="user">
        <el-dropdown>
          <span style="line-height: 48px;">
            <span class="name">
              &nbsp;
              {{ userName }}
              &nbsp;&nbsp;
            </span>

            <el-icon>
              <arrow-down />
            </el-icon>
          </span>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item>个人中心</el-dropdown-item>
              <el-dropdown-item>优化意见</el-dropdown-item>
              <el-dropdown-item divided @click="O_Logout">退出登陆</el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </div>
    </div>

  </div>
</template>

<style lang='less' scoped>
#G_Head {
  background-color: #ffffff;
  display: flex;
  height: 54px;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px 0 10px;
  box-sizing: border-box;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  min-width: 320px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);

  .function {
    display: flex;
    align-items: center;
    gap: 8px;

    .item {
      padding: 8px;
      cursor: pointer;
      border-radius: 6px;
      transition: all 0.2s ease;
      color: #606266;

      &:hover {
        background-color: #f6f8fa;
        color: var(--el-color-primary);
      }

      .el-icon {
        font-size: 18px;
        vertical-align: middle;
      }
    }

    .info {
      display: flex;
      align-items: center;
      font-size: 14px;
      margin-left: 12px;
      padding: 4px 8px;
      border-radius: 6px;
      transition: all 0.2s ease;
      cursor: pointer;

      &:hover {
        background-color: #f6f8fa;
      }

      img {
        width: 32px;
        height: 32px;
        border-radius: 50%;
        margin-right: 8px;
        border: 2px solid #fff;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
      }

      .name {
        color: #303133;
        font-weight: 500;
      }
    }
  }
}

@media screen and (max-width: 600px) {
  #G_Head {
    padding: 0 12px;

    .none {
      display: none;
    }

    .function {
      gap: 4px;

      .item {
        padding: 6px;
      }
    }
  }
}
</style>